﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using JeffWilcox.Utilities.Silverlight;
using System.Windows.Browser;
using System.Threading;
using System.IO;
using System.Text;
using System.Runtime.Serialization.Json;
using System.Reflection;
using VkApi.DataTypes;

namespace VkApi
{
    public partial class VkApi
    {
        /// <summary>
        /// Gets the list of notes created by user.
        /// </summary>
        /// <param name="uid">The user ID. (unnecessary)</param>
        /// <param name="nids">The notes IDs. (unnecessary)</param>
        /// <param name="sort">The sort. 0 by creation date increase, 1 - decrease. (unnecessary)</param>
        /// <param name="count">The count of results to return. (unnecessary)</param>
        /// <param name="offset">The offset. (unnecessary)</param>
        /// <param name="callback">The callback.</param>
        /// <returns>Array of Notes.</returns>
        public long Notes_Get(long? uid, long[] nids, int? sort, int? count, int? offset, ApiCallback<Note[]> callback)
        {
            List<Parameter> list = new List<Parameter>();
            if (uid != null) list.Add(new Parameter("uid", uid.ToString()));
            if (nids != null && nids.Length > 0)
            {
                string nidsString = "";
                foreach(long s in nids)
                    nidsString += s.ToString() + ",";
                nidsString = nidsString.Remove(nidsString.Length - 1);
                list.Add(new Parameter("nids", nidsString));
            }
            if (sort != null) list.Add(new Parameter("sort", sort.ToString()));
            if (count != null) list.Add(new Parameter("count", count.ToString()));
            if (offset != null) list.Add(new Parameter("offset", offset.ToString()));
            return this.SendRequest("notes.get", callback, list.ToArray());
        }

        /// <summary>
        /// Gets the note by its ID.
        /// </summary>
        /// <param name="nid">The note ID.</param>
        /// <param name="owner_id">The owner ID. Current user by default.(unnecessary)</param>
        /// <param name="need_wiki">The flag for wiki including. Work for current user only. (unnecessary)</param>
        /// <param name="callback">The callback.</param>
        /// <returns>NoteEx object.</returns>
        public long Notes_GetByID(long nid, long? owner_id, int? need_wiki, ApiCallback<NoteEx> callback)
        {
            List<Parameter> list = new List<Parameter>();
             list.Add(new Parameter("nid", nid.ToString()));
             if (owner_id != null) list.Add(new Parameter("owner_id", owner_id.ToString()));
             if (need_wiki != null) list.Add(new Parameter("need_wiki", need_wiki.ToString()));           
            return this.SendRequest("notes.getById", callback, list.ToArray());
        }

        /// <summary>
        /// Gets all friends notes.
        /// </summary>
        /// <param name="count">The count of results to return. (unnecessary)</param>
        /// <param name="offset">The offset. (unnecessary)</param>
        /// <param name="callback">The callback.</param>
        /// <returns>Array of Note.</returns>
        public long Notes_GetFriendsNotes(int? count, int? offset, ApiCallback<Note[]> callback)
        {
            List<Parameter> list = new List<Parameter>();
            if (count != null) list.Add(new Parameter("count", count.ToString()));
            if (offset != null) list.Add(new Parameter("offset", offset.ToString()));
            return this.SendRequest("notes.getFriendsNotes", callback, list.ToArray());
        }

        /// <summary>
        /// Adds the note.
        /// </summary>
        /// <param name="title">The title of the note.</param>
        /// <param name="text">The text of the note.</param>
        /// <param name="privacy">The privacy. 0 - all users, 1 - friends only, 2 - friends and friends of friends, 3 - only user. (unnecessary)</param>
        /// <param name="comment_privacy">The comment privacy. 0 - all users, 1 - friends only, 2 - friends and friends of friends, 3 - only user. (unnecessary)</param>
        /// <param name="callback">The callback.</param>
        /// <returns>Note ID if success.</returns>
        public long Notes_Add(string title, string text, int? privacy, int? comment_privacy, ApiCallback<long> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("title", title));
            list.Add(new Parameter("text", text));
            if (privacy != null) list.Add(new Parameter("privacy", privacy.ToString()));
            if (comment_privacy != null) list.Add(new Parameter("comment_privacy", comment_privacy.ToString()));
            return this.SendRequest("notes.add", callback, list.ToArray());
        }

        /// <summary>
        /// Edits the note.
        /// </summary>
        /// <param name="nid">The node ID.</param>
        /// <param name="title">The title of the note.</param>
        /// <param name="text">The text of the note.</param>
        /// <param name="privacy">The privacy. (unnecessary)</param>
        /// <param name="comment_privacy">The comment privacy. (unnecessary)</param>
        /// <param name="callback">The callback.</param>
        /// <returns>1 if success.</returns>
        public long Notes_Edit(long nid, string title, string text, int? privacy, int? comment_privacy, ApiCallback<long> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("nid", nid.ToString()));
            list.Add(new Parameter("title", title));
            list.Add(new Parameter("text", text));
            if (privacy != null) list.Add(new Parameter("privacy", privacy.ToString()));
            if (comment_privacy != null) list.Add(new Parameter("comment_privacy", comment_privacy.ToString()));
            return this.SendRequest("notes.edit", callback, list.ToArray());
        }

        /// <summary>
        /// Deletes the note by its ID.
        /// </summary>
        /// <param name="nid">The note ID.</param>
        /// <param name="callback">The callback.</param>
        /// <returns>1 if success.</returns>
        public long Notes_Delete(long nid, ApiCallback<long> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("nid", nid.ToString()));            
            return this.SendRequest("notes.delete", callback, list.ToArray());
        }

        /// <summary>
        /// Gets the list of comments to the note.
        /// </summary>
        /// <param name="nid">The note ID.</param>
        /// <param name="owner_id">The user ID. Current user by default. (unnecessary)</param>
        /// <param name="sort">The sort. 0 by creation date increase, 1 - decrease. (unnecessary)</param>
        /// <param name="count">The count of results to return. (unnecessary)</param>
        /// <param name="offset">The offset. (unnecessary)</param>
        /// <param name="callback">The callback.</param>
        /// <returns>Array of CommentEx[]</returns>
        public long Notes_GetComments(long nid, long? owner_id, int? sort, int? count, int? offset, ApiCallback<CommentEx[]> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("nid", nid.ToString()));
            if (owner_id != null) list.Add(new Parameter("owner_id", owner_id.ToString()));
            if (sort != null) list.Add(new Parameter("sort", sort.ToString()));
            if (count != null) list.Add(new Parameter("count", count.ToString()));
            if (offset != null) list.Add(new Parameter("offset", offset.ToString()));
            return this.SendRequest("notes.getComments", callback, list.ToArray());
        }

        /// <summary>
        /// Creates the new comment for the note.
        /// </summary>
        /// <param name="nid">The note ID.</param>
        /// <param name="owner_id">The owner ID. Current user by default. (unnecessary)</param>
        /// <param name="reply_to">The reply to. (unnecessary)</param>
        /// <param name="message">The message text.</param>
        /// <param name="callback">The callback.</param>
        /// <returns>New comment ID or error code.</returns>
        public long Notes_CreateComment(long nid, long? owner_id, long? reply_to, string message, ApiCallback<long> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("nid", nid.ToString()));
            if (owner_id != null) list.Add(new Parameter("owner_id", owner_id.ToString()));
            if (reply_to != null) list.Add(new Parameter("reply_to", reply_to.ToString()));
            list.Add(new Parameter("message", message));            
            return this.SendRequest("notes.createComment", callback, list.ToArray());
        }

        /// <summary>
        /// Edits the comment for the note.
        /// </summary>
        /// <param name="cid">The comment ID.</param>
        /// <param name="owner_id">The owner ID. Current user by default. (unnecessary)</param>
        /// <param name="message">The new message text.</param>
        /// <param name="callback">The callback.</param>
        /// <returns>1 if success.</returns>
        public long Notes_EditComment(long cid, long? owner_id, string message, ApiCallback<int> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("cid", cid.ToString()));
            if (owner_id != null) list.Add(new Parameter("owner_id", owner_id.ToString()));           
            list.Add(new Parameter("message", message));
            return this.SendRequest("notes.editComment", callback, list.ToArray());
        }

        /// <summary>
        /// Deletes the comment.
        /// </summary>
        /// <param name="cid">The comment ID.</param>
        /// <param name="owner_id">The owner ID. Current user by default. (unnecessary)</param>
        /// <param name="callback">The callback.</param>
        /// <returns>1 if success.</returns>
        public long Notes_DeleteComment(long cid, long? owner_id,ApiCallback<int> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("cid", cid.ToString()));
            if (owner_id != null) list.Add(new Parameter("owner_id", owner_id.ToString()));           
            return this.SendRequest("notes.deleteComment", callback, list.ToArray());
        }

        /// <summary>
        /// Restores the comment.
        /// </summary>
        /// <param name="cid">The comment ID.</param>
        /// <param name="owner_id">The owner ID. Current user by default. (unnecessary)</param>
        /// <param name="callback">The callback.</param>
        /// <returns>1 if success.</returns>
        public long Notes_RestoreComment(long cid, long? owner_id, ApiCallback<int> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("cid", cid.ToString()));
            if (owner_id != null) list.Add(new Parameter("owner_id", owner_id.ToString()));
            return this.SendRequest("notes.restoreComment", callback, list.ToArray());
        }



    }
}
